package com.shared.controller;
import com.shared.pojo.PComment;
import com.shared.pojo.PGoods;
import com.shared.pojo.PGoodsAlbum;
import com.shared.pojo.PGoodsCover;
import com.shared.server.PGoodsAalbumServer;
import com.shared.server.PGoodsServer;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import java.util.Set;

@Controller
public class PGoodsController {

    @Autowired
    private PGoodsServer pGoodsServer;
    @Autowired
    private PGoodsAalbumServer pGoodsAalbumServer;

    @GetMapping(value = "/hello")
    @ResponseBody
    public String hello() {
        return "hello";
    }

    @GetMapping("/goods")
    @ResponseBody
    @ApiOperation(value = "查询所有商品信息")
    public List<PGoods> findAllGoods() {
        return pGoodsServer.findAllGoods();
    }

    @GetMapping("/pgoods/{id}")
    @ResponseBody
    @ApiOperation(value = "根据id查询商品")
    public List<PGoods> pGoods(@PathVariable("id") Integer id) {
        return pGoodsServer.findById(id);
    }

    @GetMapping("/pgo/{id}")
    @ResponseBody
    @ApiOperation(value = "查询id查询商品信息")
    public List<PGoods> pGoo(@PathVariable("id") Integer id) {
        return pGoodsServer.findById(id);
    }

    @GetMapping("/album/{id}")
    @ResponseBody
    @ApiOperation(value = "查询id查询商品详情轮播图")
    public List<PGoodsAlbum> pGoodsAlbum(@PathVariable("id") Integer id) {
        return pGoodsAalbumServer.findAlbumByGid(id);
    }

    @GetMapping("/cover/{id}")
    @ResponseBody
    @ApiOperation(value = "查询id查询商品详情信息")
    public List<PGoodsCover> pGoodsCovers(@PathVariable("id") Integer id) {
        return pGoodsServer.findCoverByGid(id);
    }

    @GetMapping("/comment/{id}")
    @ResponseBody
    @ApiOperation(value = "查询id查询商品评论")
    public List<PComment> pComments(@PathVariable("id") Integer id) {
        return pGoodsServer.findCommentByGid(id);
    }

    @GetMapping("/goods/{TYPE}")
    @ResponseBody
    @ApiOperation(value = "根据商品种类查询商品信息")
    public List<PGoods> pGoodsType(@PathVariable("TYPE") Integer TYPE) {
        return pGoodsServer.findGoodsByTYPE(TYPE);
    }


}
